import { createRouter, createWebHistory, createWebHashHistory, type RouteRecordRaw } from "vue-router";
import { mainBaseAppRouter } from "@/microApp/utils";

const Layout = () => import("@/layout/index.vue");

export const constantRoutes: RouteRecordRaw[] = [
  {
    path: "/redirect",
    component: Layout,
    meta: {
      hidden: false
    },
    children: [
      {
        path: "/redirect/:path(.*)",
        meta: { hidden: true },
        component: () => import("@/views/redirect/index.vue")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: false }
  },
  {
    path: "/pdfPreview",
    component: () => import("@/views/pdfPreview/index.vue"),
    meta: { hidden: false }
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error/404.vue"),
    meta: { hidden: false }
  },
  {
    path: "/403",
    component: () => import("@/views/error/403.vue"),
    meta: { hidden: false }
  },
  {
    path: "/",
    name: "Home",
    component: Layout,
    redirect: "/home",
    meta: { title: "任务工作台", hidden: true, icon: "staging" },
    children: [
      {
        path: "/home",
        component: () => import("@/views/home/index.vue"),
        name: "Home",
        meta: { title: "首页", icon: "staging", svgIcon: "staging", affix: true, hidden: true }
      }
    ]
  },
  // crm——子应用
  {
    path: "/",
    name: "crmIndex",
    component: Layout,
    meta: { title: "crmIndex", hidden: false },
    children: [
      {
        path: "/crm/:page*",
        component: () => import("@/views/crm/index.vue"),
        meta: { keepAlive: true },
        name: "crm"
      }
    ]
  },
  // 设计需求表——子应用
  {
    path: "/",
    name: "designFormIndex",
    component: Layout,
    meta: { title: "designFormIndex", hidden: false },
    children: [
      {
        path: "/designForm/:page*",
        component: () => import("@/views/designForm/index.vue"),
        meta: { keepAlive: true },
        name: "designForm"
      }
    ]
  },
  // 工程管理——子应用
  {
    path: "/",
    name: "engineeringIndex",
    component: Layout,
    meta: { title: "engineeringIndex", hidden: false },
    children: [
      {
        path: "/projectmanage/:page*",
        component: () => import("@/views/engineering/index.vue"),
        name: "projectmanage"
      }
    ]
  },
  // 销售合同管理——子应用
  {
    path: "/",
    name: "salesContractIndex",
    component: Layout,
    meta: { title: "salesContractIndex", hidden: false, icon: "contract" },
    children: [
      {
        path: "/sales-contract/:page*",
        component: () => import("@/views/salesContract/index.vue"),
        name: "sales-contract",
        meta: { title: "销售合同管理", icon: "contract", svgIcon: "contract", affix: true, hidden: true }
      }
    ]
  },
  // flow——子应用
  {
    path: "/",
    name: "formIndex",
    component: Layout,
    meta: { title: "formIndex", hidden: false },
    children: [
      {
        path: "/form-design/:page*",
        component: () => import("@/views/forms/index.vue"),
        name: "form-design"
      }
    ]
  },
  // 合同模板——子应用
  {
    path: "/",
    name: "contractTemplate",
    component: Layout,
    meta: { title: "contractTemplate", hidden: false },
    children: [
      {
        path: "/contract-template/:page*",
        component: () => import("@/views/contractTemplate/index.vue"),
        name: "contract-template"
      }
    ]
  },
  // 工厂端——子应用
  {
    path: "/",
    name: "factoryIndex",
    component: Layout,
    meta: { title: "factoryIndex", hidden: false },
    children: [
      {
        path: "/factory/:page*",
        component: () => import("@/views/factory/index.vue"),
        name: "factory"
      }
    ]
  },
  // 商家端——子应用
  {
    path: "/",
    name: "businessIndex",
    component: Layout,
    children: [
      {
        path: "/business/:page*",
        component: () => import("@/views/business/index.vue"),
        name: "business"
      },
      {
        path: "/business/vmi/add",
        component: () => import("@/views/business/vmi/add.vue"),
        name: "business-vmi-add"
      },
      {
        path: "/business/vmi/edit",
        component: () => import("@/views/business/vmi/edit.vue"),
        name: "business-vmi-edit"
      }
    ]
  },
  // 设计师商城——子应用
  {
    path: "/designer/:page*",
    component: () => import("@/views/designer/index.vue"),
    name: "designer",
    meta: { hidden: false }
  },
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "/stencil/:page*",
        component: () => import("@/views/stencil/index.vue"),
        name: "stencil"
      }
    ]
  },
  {
    path: "/",
    name: "User",
    component: Layout,
    redirect: "/user",
    meta: { title: "个人中心", hidden: false },
    children: [
      {
        path: "/user",
        component: () => import("@/views/userInfo/index.vue"),
        name: "User",
        meta: { title: "个人中心", icon: "icon-dashboard", svgIcon: "menu-home", affix: true, hidden: false }
      }
    ]
  },
  {
    path: "/",
    name: "Audit",
    component: Layout,
    redirect: "/audit",
    meta: { title: "首页", hidden: false },
    children: [
      {
        path: "/audit",
        component: () => import("@/views/audit/index.vue"),
        name: "Audit",
        meta: { title: "审批", icon: "icon-dashboard", svgIcon: "menu-home", affix: true, hidden: false }
      }
    ]
  },
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "/finance/:page*",
        component: () => import("@/views/finance/index.vue"),
        name: "finance"
      }
    ]
  },
  {
    path: "/",
    name: "MessageList",
    component: Layout,
    redirect: "/message-list",
    meta: { title: "首页", hidden: false },
    children: [
      {
        path: "/message-list",
        component: () => import("@/views/home/messageAllList/index.vue"),
        name: "MessageList",
        meta: { title: "消息", icon: "icon-dashboard", svgIcon: "menu-home", affix: true, hidden: false }
      }
    ]
  },
  // 集采
  {
    path: "/",
    component: Layout,
    name: "centralizedProcurement",
    children: [
      {
        path: "/centralized-procurement/:page*",
        component: () => import("@/views/centralizedProcurement/index.vue"),
        name: "centralized-procurement"
      }
    ]
  },
  // 代理商
  {
    path: "/",
    component: Layout,
    name: "commissionAgent",
    children: [
      {
        path: "/commission-agent/:page*",
        component: () => import("@/views/commissionAgent/index.vue"),
        name: "commission-agent"
      }
    ]
  }
];

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: constantRoutes,
  scrollBehavior: () => ({ left: 0, top: 0 })
});

mainBaseAppRouter(router);

export default router;
